package net.towee.model.discussion.impl;

import java.util.Date;

import net.towee.model.account.AccountIdentity;
import net.towee.model.discussion.Message;

import com.google.code.morphia.annotations.Embedded;
import com.google.code.morphia.annotations.Indexed;
import com.google.code.morphia.annotations.Reference;

/**
 * Message implementation
 * @author c58
 */
@Embedded
public class MessageImpl implements Message {
	@Indexed private String id;
	@Reference private AccountIdentity author;
	private String text;
	private Date creationDate;
	
	public MessageImpl() {}
	public MessageImpl(String id) {
		this.id = id;
	}
	public MessageImpl(AccountIdentity author, String text, String id) {
		this.author = author;
		this.creationDate = new Date();
		this.text = text;
		this.id = id;
	}
	
	@Override
	public String getId() {
		return id;
	}
	
	@Override
	public void setId(String id){
		this.id = id;
	}

	@Override
	public AccountIdentity getAuthor() {
		return author;
	}

	@Override
	public Date getCreationDate() {
		return creationDate;
	}

	@Override
	public String getText() {
		return text;
	}

	@Override
	public void setText(String text) {
		this.text = text;
	}
	@Override
	public void setAuthor(AccountIdentity accountIdentity) {
		this.author = accountIdentity;
	}

	@Override
	public boolean equals(Object o) {
		if(o == this)
			return true;
		if(o instanceof Message && getId().equals( ((Message) o).getId() ))
			return true;
		
		return false;
	}
}
